package com.smart.common.utils.redis.redistask;

import com.smart.common.utils.redis.RedisManager;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RedisStringTask implements Runnable {

    private final static Logger redisLogger = LoggerFactory.getLogger("redisLogger");

    private RedisManager redisManager;
    private String key;
    private String value;
    private int index;

    public RedisStringTask(RedisManager redisManager, String key, String value, int index) {
        this.redisManager = redisManager;
        this.key = key;
        this.value = value;
        this.index = index;
    }


    @Override
    public void run() {
        String setRedisString = redisManager.setRedisString(key, value, index);
        if (StringUtils.isBlank(setRedisString)) {
            //记录失败日志
            redisLogger.error("error:更新失败:key=" + key + ",value=" + value);
        } else {
            if (StringUtils.isBlank(redisManager.getRedisString(key, index))) {
                //记录失败日志
                redisLogger.error("error:更新失败:key=" + key + ",value=" + value);
            }
        }
    }
}
